package logic.login_logic;


import javaRMI.RMIClient;

import logicsv.login_logicsv.UserType;
import po.UserPO;
import resultmessage.LoginRM;
import datasv.datafactorysv.LoginDatasvFactory;
import datasv.login_datasv.LoginDatasv;

public class Login {
	private LoginDatasv loginData;
	public Login(RMIClient rmi){
		LoginDatasvFactory ldf = new LoginDatasvFactory(rmi);
		loginData = ldf.create();
	}
	/**return the id type*/
	public UserType getUserType(String id){
		return UserType.getUserType(id);
	}
	/** use the id and password user has input to login
	 * @return ResultMessage an enum about the login result
	 * */
	public LoginRM login(String id, String password) {
		UserPO user = loginData.findUser(id);
		if(user == null){
			return LoginRM.NO_EXIST_ID;
		}
		if(user.getPassword().equals(password)){
			return LoginRM.SUCCESS;
		}else{
			return LoginRM.WRONG_PASSWORD;
		}
	}
//	public static void main(String[] args) throws MalformedURLException, RemoteException, NotBoundException{
//		Login logger1 = new Login("121250143","112");
//		System.out.println(logger1.login());
//		Login logger2 = new Login("121250143","121250143");
//		System.out.println(logger2.login());
//		Login logger3 = new Login("1250143","121250143");
//		System.out.println(logger3.getUserType());
//	}
//	protected static ResultMessage judgeResult(String id,String password){
//		return judge(id, password);
//	}
//	private static ResultMessage judge(String id,String password){
//		UserPO po=new UserPO("123456","123456");
//		if(po.getID().equals("123456")&&po.getPassword().equals("123456")){
//			return ResultMessage.SUCCESS;
//		}
//		return ResultMessage.NO_EXIST_ID;
//	} 
////	public Identity get
}
